﻿using System;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using System.Collections;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.ACTP
{
    public enum ModulePages
    {
        MyCalendar,
        TeamCalendar,
        TeamList,
        TeamSearch,
        ProjectCalendar,
        ProjectGanttChart,
        ProjectList,
        ProjectDetail,
        ProjectSearch,
        ProjectSchedule,
        TaskList,
        TaskSearch,
        DocumentList,
        EmployeeList,
        EmployeeSearch,
        EmployeeDetail,
        CertificationList,
        CertificationSearch
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Storage file type.
            ArrayList listStorageType = new ArrayList();
            listStorageType.Add(new ListItem("Database", "DATABASE"));
            listStorageType.Add(new ListItem("Link", "LINK"));
            listStorageType.Add(new ListItem("File", "FILE"));

            ModuleSettingItem setting = new ModuleSettingItem(new CustomListDataType(listStorageType, "Text", "Value"));
            setting.Value = "DATABASE";
            setting.Name = "Storage Type";
            setting.Description = "Storage Type";
            setting.SortOrder = 10;
            this.BaseSettings.Add("StorageType", setting);

            setting = new ModuleSettingItem(new BooleanDataType(true));
            setting.Name = "Bool";
            setting.Description = "Desc";
            setting.SortOrder = 11;
            this.BaseSettings.Add("Bool", setting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.ACTP/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page = ModulePages.ProjectList;
            if (pageName != null)
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.LoadChildControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
            }
        }

        //protected void btnProject_Click(object sender, EventArgs e)
        //{
        //    string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.ProjectList);
        //    Response.Redirect(url);
        //}

        //protected void btnTask_Click(object sender, EventArgs e)
        //{
        //    string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.TaskList);
        //    Response.Redirect(url);
        //}

        //protected void btnDocument_Click(object sender, EventArgs e)
        //{
        //    string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.DocumentList);
        //    Response.Redirect(url);
        //}

        //protected void btnEmployee_Click(object sender, EventArgs e)
        //{
        //    string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.EmployeeList);
        //    Response.Redirect(url);
        //}
    }
}